#include "core/gateway_config.h"
#include "core/device_manager.h"

GatewayConfig::GatewayConfig() { setDefaults(); }

void GatewayConfig::setDefaults() {
    m_deviceConfigs.clear();
    auto& manager = DeviceManager::getInstance();
    std::vector<std::string> device_list = manager.listAvailableDevices();
    // Temporarily default settings, maybe it is not suitable.
    for (const auto& device_name : device_list) {
        DeviceConfig config;
        config.name = device_name;
        config.promiscuous = true;
        config.buffer_size = 64 * 1024 * 1024;    // 64Mb
        config.timeout_ms = 100;
        config.filter = "ip";                     // only capture ip packet
        m_deviceConfigs.emplace_back(config);
    }
}

bool GatewayConfig::loadFromFile(const std::string& filename) {
    // complete later
    return true;
}

bool GatewayConfig::loadFromCommandLine(int argc, char* argv[]) {
    // complete later
    return true;
}

bool GatewayConfig::validate() const {
    // basic check
    if (m_deviceConfigs.empty()) {
        return false;
    }
    /*
    for (const auto& deviceConfig : m_deviceConfigs) {
        if (deviceConfig.name.empty()) {
            return false;
        }
    }
    */
    return true;
}